Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup TagField to work within AssetAdmin (Fixes #107) #120

Merged
merged 6 commits into from
Jul 25, 2019
Merged

Setup TagField to work within AssetAdmin (Fixes #107) #120

merged 6 commits into from
Jul 25, 2019

Conversation

wilr
Copy link
Member

@wilr wilr commented Oct 10, 2018

Form field now appears, can be added and searched.

This also fixes missing label
screen shot 2018-10-10 at 4 05 55 pm

@wilr wilr changed the title WIP: Setup TagField to work within AssetAdmin (Fixes #107) Setup TagField to work within AssetAdmin (Fixes #107) Oct 10, 2018
client/src/components/TagField.js Outdated Show resolved Hide resolved
src/TagField.php Outdated Show resolved Hide resolved
src/TagField.php Outdated Show resolved Hide resolved
@robbieaverill
Copy link
Contributor

robbieaverill commented Nov 15, 2018

I think this PR mostly looks good, but there's a couple of breaking changes that would need to be adjusted and polished. Also I've just made a PR at #122 which will cause a couple of conflicts with adding the same logic in this PR in places

@wilr
Copy link
Member Author

wilr commented Nov 15, 2018

Happy if @robbieaverill you want to incorporate the bits needed into #122 and close this.

@robbieaverill
Copy link
Contributor

@wilr I might try and do it on bug day tomorrow

@robbieaverill robbieaverill self-assigned this Nov 16, 2018
@robbieaverill
Copy link
Contributor

(Context: #122 with these changes applied)

Hrmmm, I've got the fields rendering correctly in asset admin but when I have 'name' => $this->getName() . '[]'; redux-form won't validate or store the tag values correctly, which means (A) it won't add the tag in the UI and (B) it won't save it (related issue: silverstripe/silverstripe-admin#639)

If I use a regular $this->getName(), tags end up getting pushed into the DOM in multiple hidden inputs with the same name.

Does this PR actually save @wilr?

@ScopeyNZ are you able to provide any advice here in terms of how this field interacts with redux-form? Again related: silverstripe/silverstripe-admin#639

@robbieaverill robbieaverill removed their assignment Nov 16, 2018
@wilr
Copy link
Member Author

wilr commented Nov 16, 2018

@robbieaverill Yep saves perfectly, been running in prod for a couple weeks now. But this is using composer.lock (https://gist.github.com/wilr/68ed4e6eb9f063da4e00dec6831e0a98). Note the [] was to copy how CheckboxSetField passed its' array.

@robbieaverill robbieaverill self-assigned this Nov 19, 2018
@robbieaverill
Copy link
Contributor

@wilr In this PR I've noticed that I get an undefined index error when using the fields on a non-React form, and that StringTagField isn't working in the React context yet. It does look like this PR does make TagField work correctly in a React context, so thank you for that! I'll try and work out why #122 isn't based off of this and move it to that.

@robbieaverill
Copy link
Contributor

Yeah OK, I can get it working in either entwine or React context but not both at the same time (this PR is the same). I've raised an issue at silverstripe/silverstripe-admin#755 for tracking. I suspect we'll have to refactor more of the logic in TagField to get this to work, and probably do as you've suggested here and switch to extending MultiSelectField.

I'll leave this PR open

@ScopeyNZ
Copy link
Contributor

It took me wayyyy too long but I finally got around to having a go at fixing this. I've tested this using the blog module and using elemental in-line editing to render a tag field in the React context.

For the react context you'll need the admin PR merged as a dependency (silverstripe/silverstripe-admin#912) otherwise the values won't appear in the field.

@robbieaverill
Copy link
Contributor

@ScopeyNZ is that the only dependency for this PR, e.g. once the admin PR is merged will this PR fix the original issue?

@ScopeyNZ
Copy link
Contributor

Yeah we spoke about this a little offline. The admin PR ensures that the field value is correctly set from redux state. So I think this only matters in the elemental context.

Copy link
Contributor

@ScopeyNZ ScopeyNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Reviewing" so that I can stop being a requested reviewer 😅

Copy link

@NightJar NightJar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When viewing a BlogPost and creating tags, everything works fine.
On saving a BlogPost with new tags, everything works fine.
On saving a BlogPost with existing tags, everything is not fine.

  • Current tags are removed from the relationship
  • An equal number of new tags are created and assigned to the relationship
  • These new tags have the Title and URLSegment of the ID field of the tags they're replacing.

Reproduction

Create a BlogPost
Assign tags "one" and "two" (two separate tags).
Save - See "one" and "two" assigned.
Reload - see "one" and "two" assigned.
Save - see "1" and "2" assigned.
Save - see "3" and "4" assigned.
Save - see "5" and "6" assigned.
Reload - see "5" and "6" assigned.

Environment

    "repositories": [
        {
            "type": "vcs",
            "url": "[email protected]:creative-commoners/silverstripe-admin"
        },
        {
            "type": "vcs",
            "url": "https://github.com/wilr/silverstripe-tagfield/"
        }
    ],
    "require": {
        "silverstripe/recipe-plugin": "^1",
        "silverstripe/recipe-cms": "^4.4",
        "dnadesign/silverstripe-elemental": "^4.3",
        "silverstripe/elemental-fileblock": "^2.0",
        "silverstripe/elemental-bannerblock": "^2.0",
        "silverstripe/blog": "^3.3",
        "silverstripe/admin": "dev-pulls/1.4/field-names-in-disarray as 1.4.1",
        "silverstripe/tagfield": "dev-fixes/107-tagfield-in-admin as 2.3.0"
    },

Testing as per #107 OP seems to work fine. Tags do not appear to "duplicate" themselves.

@ScopeyNZ
Copy link
Contributor

Thanks @NightJar . There was some confusion about IDs vs label titles. Should be squared away now.

Copy link
Contributor

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small questions. Let's also make this a minor release rather than a patch, because we're adding some new APIs, replacing the react-select library with a newer one, and changing the API response structure

client/src/components/TagField.js Outdated Show resolved Hide resolved
client/src/components/TagField.scss Outdated Show resolved Hide resolved
src/TagField.php Outdated Show resolved Hide resolved
@NightJar
Copy link

Thanks @ScopeyNZ - can confirm latest update has resolved that issue :)

@NightJar NightJar dismissed their stale review July 24, 2019 23:08

Issues identified were fixed.

wilr and others added 5 commits July 25, 2019 12:13
This also fixes an issue where tags would be created and tags could not have the same name as the ID of an existing tag
And the react-select module is updated to the (current) latest 1.x version
And the tests are now working again after updating jest
@ScopeyNZ ScopeyNZ changed the base branch from 2.3 to master July 25, 2019 00:26
@ScopeyNZ
Copy link
Contributor

Ok I've addressed feedback and rebased for a minor release. Thanks for the review @robbieaverill & @NightJar!

@robbieaverill robbieaverill merged commit 58edb12 into silverstripe:master Jul 25, 2019
@robbieaverill
Copy link
Contributor

Good result everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants